import Vue from "vue";
import VueRouter from "vue-router";

import { RoutesTool } from "@/utils/RouteTool";
import { ViewItems } from "@/views/ViewItems";

Vue.use(VueRouter);

const routes = RoutesTool.Layout(
  RoutesTool.Routes(ViewItems.GetInstance().Groups)
);

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  scrollBehavior: (to, from, savedPosition) => {
    // 让每次的导航回到相同的位置
    // 现在不知道具体用处
    if (to.hash) {
      return { selector: to.hash };
    }

    if (savedPosition) {
      return savedPosition;
    }

    return { x: 0, y: 0 };
  },
  routes: [routes]
});

export default router;
